##============================================================================#
# Copyright © hk. 2022-2025. All rights reserved.
# File name: Makefile
# Author   : 苏木
# Date     : 2024-08-12
# Version  : 
# Description: 
##============================================================================#
##
TARGET         ?= aes_128
TEST_DATA_PATH  = ~/1sharedfiles/test/aes/
OBJ      = main.o aes_core.o

INCDIRS += ./
INCLUDE := $(patsubst %, -I %, $(INCDIRS))

CC              = gcc
CFLAGS         += -g -Wall
#GIT_SHA         = $(shell git rev-list HEAD | awk 'NR==1')
GIT_SHA         = $(shell git rev-parse --short HEAD | awk 'NR==1')
GIT_SEQ         = $(shell git rev-list HEAD | wc -l)
GIT_VER_INFO    = $(GIT_SHA)-$(GIT_SEQ)
GIT_SVR_PATH    = $(shell git remote -v | awk 'NR==1' | sed 's/[()]//g' | sed 's/\t/ /g' |cut -d " " -f2)

ifneq ($(GIT_VER_INFO),)
	CFLAGS     += -DGIT_VERSION=\"$(GIT_VER_INFO)\"
else
	CFLAGS     += -DGIT_VERSION=\"unknown\"
endif

ifneq ($(GIT_SVR_PATH),)
	CFLAGS     += -DGIT_PATH=\"$(GIT_SVR_PATH)\"
else
	CFLAGS     += -DGIT_PATH=\"unknown\"
endif

$(TARGET): ${OBJ}
	$(CC) $(CFLAGS) $(OBJ) -o $(TARGET)

$(OBJ):%.o:%.c
	$(CC) $(CFLAGS) -c $(INCLUDE) $< -o $@

.PHONY: clean
clean:
	rm -rf *.o $(TARGET)

cpy:
	@cp -v $(TARGET) $(TEST_DATA_PATH)